package com.xxyf.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.fasterxml.jackson.databind.JsonNode;
import com.xxyf.service.UsernameService;
import com.xxyf.tools.Rest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @Author 小小怡飞
 * @Date 2022/9/1 5:27
 * @Version JDK 8
 */
@RestController
@RequestMapping("/login.do")
@Api(tags = "登录模块")
@Slf4j
public class Userlogin {
    @Autowired
    private UsernameService service;

    @ApiOperation("验证用户名登录")
    @PostMapping
    private Rest lodging(@ApiParam("json传入account与password") @RequestBody Map<String,String> login, HttpSession session){
        session.setAttribute("key","values");
        log.error("ID"+session.getId());
        String user = login.get("user");
        String pass =  login.get("pass");
        return service.login(user,pass);

    }
    @ApiOperation("注册检测用户是否存在")
    @GetMapping("/check/{id}")
    private Rest check(@PathVariable("id") String id){
        return service.check(id);
    }
    @ApiOperation("注册用户")
    @GetMapping("/reg")
    private Rest reg(String account,String password,String newPass){
        return service.reg(account,password,newPass);
    }
}
